package com.csc.banking.dao;

import javax.persistence.EntityManager;

import org.hibernate.Transaction;
import org.springframework.stereotype.Repository;

import com.csc.banking.domain.Currency;
import com.csc.banking.domain.PeriodType;
import com.csc.banking.domain.Role;
import com.csc.banking.domain.SystemUser;
import com.csc.banking.util.CustomEntityManager;
import com.csc.banking.util.CustomHibernateDaoSupport;
@Repository
public class Test  {
	
	public Role getRole(){
		EntityManager em = CustomEntityManager.createEntityManager();
		
		em.getTransaction().begin();
		Role role= em.find(Role.class, 1);
		em.getTransaction().commit();
		return role;
		
	}
	
	public void addRole(Role role)
	{
		try {
			EntityManager em = CustomEntityManager.createEntityManager();
			em.getTransaction().begin();	
			em.persist(role);		
			em.getTransaction().commit();
		
		} catch (Exception e) {
			System.out.println("abcdddddd");
			e.printStackTrace();
		}
		
		
	}
	
	
	public void addUser(SystemUser u)
	{
		try {
			EntityManager em = CustomEntityManager.createEntityManager();
			em.getTransaction().begin();
			Role role= em.find(Role.class, 1);
			u.setRoles(role);
			em.persist(u);		
			em.getTransaction().commit();
		
		} catch (Exception e) {
			System.out.println("abcdddddd");
			e.printStackTrace();
		}
	}
	
	public void addCurrencty(Currency c)
	{
		try {
			EntityManager em = CustomEntityManager.createEntityManager();
			em.getTransaction().begin();
				
			em.persist(c);		
			em.getTransaction().commit();
		
		} catch (Exception e) {
			System.out.println("abcdddddd");
			e.printStackTrace();
		}
		
	}
	public void  addperiod(PeriodType p)
	{
		try {
			EntityManager em = CustomEntityManager.createEntityManager();
			em.getTransaction().begin();
				
			em.persist(p);		
			em.getTransaction().commit();
		
		} catch (Exception e) {
			System.out.println("abcdddddd");
			e.printStackTrace();
		}
		
	}
}
